package gold.digger;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC1248 {
    public long startExecuteTime = System.currentTimeMillis();

    /*
     * @param 此题目参考了别人代码
     * 这是因为问题情况较为复杂
     * 未来需要再次复习此道题目
     * 不得不说，这个解法实在是太秀了！
     */
    class Solution {
        public int numberOfSubarrays(int[] nums, int k) {
            int n = nums.length;
            int[] cnt = new int[n + 1];
            int odd = 0, ans = 0;
            cnt[0] = 1;
            for (int i = 0; i < n; ++i) {
                odd += nums[i] & 1;
                ans += odd >= k ? cnt[odd - k] : 0;
                cnt[odd] += 1;
            }
            return ans;
        }
    }


    public void run() {
        Solution solution = new Solution();
        List<Integer> list = new ArrayList<>();
        System.out.println(solution.toString());
    }

    public static void main(String[] args) throws Exception {
        LC1248 an = new LC1248();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
